<!DOCTYPE html>
<html>
<head>
	<title></title>
	<script type="text/javascript">
		
		var str = "Visit W3School,Visit W4School,Visit W5School,Visit W6School"; 
var patt = new RegExp("W(\d)School","g");
var result;

while ((result = patt.exec(str)) != null)  {
	console.log(JSON.stringify(result))
  document.write(result);
  document.write("<br />");
  document.write(patt.lastIndex);
 }
	</script>
</head>
<body>

</body>
</html>